package com.packagetracker.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import android.widget.Toast;

public class AppUtil {
	
	public static void showToastShort(final Activity activity, final int resId) {
		AppUtil.showToastShort(activity, activity.getText(resId).toString());
	}
	
	public static void showToastShort(final Activity activity, final String text) {
		Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
	}
	
	public static void showToastLong(final Activity activity, final int resId) {
		AppUtil.showToastLong(activity, activity.getText(resId).toString());
	}
	
	public static void showToastLong(final Activity activity, final String text) {
		Toast.makeText(activity, text, Toast.LENGTH_LONG).show();
	}
	
	public static ImageView createImageView(final Context activity, final int width, final int height, final int res) {
		final ImageView image = new ImageView(activity);
		image.setAdjustViewBounds(true);
		image.setScaleType(ImageView.ScaleType.FIT_CENTER);
		image.setMaxHeight(height);
		image.setMaxWidth(width);
		image.setImageResource(res);
		
		return image;
	}
	
	public static Drawable resizeImage(final Context context, final int width, final int height, final int res) {
		final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), res);
		
		final Matrix matrix = new Matrix();
		matrix.postScale((((float)width) / width), (((float)height) / height));
		
		return new BitmapDrawable(Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true));
	}
	
}